import request from '@/utils/request'

// 获取任务列表
export function getTaskList(params) {
  return request({
    url: '/task/list',
    method: 'get',
    params
  })
}

// 创建任务
export function createTask(data) {
  return request({
    url: '/task/create',
    method: 'post',
    data
  })
}

// 更新任务
export function updateTask(data) {
  return request({
    url: '/task/update',
    method: 'put',
    data
  })
}

// 删除任务
export function deleteTask(id) {
  return request({
    url: `/task/delete/${id}`,
    method: 'delete'
  })
}

// 获取任务详情
export function getTaskDetail(id) {
  return request({
    url: `/task/${id}`,
    method: 'get'
  })
}

// 执行任务
export function executeTask(id, params) {
  return request({
    url: `/task/submit/${id}`,
    method: 'post',
    data: params
  })
}

// 停止任务
export function stopTask(id, savepoint) {
  return request({
    url: `/task/stop/${id}?savepoint=${savepoint}`,
    method: 'get'
  })
} 

// 预检topic
export function checkKafkaTopic(id) {
  return request({
    url: `/task/checkkafkatopic/${id}`,
    method: 'get'
  })
}

// 批量启动任务
export function batchStartTasks(taskIds) {
  return request({
    url: '/task/submit/batch',
    method: 'post',
    data: { taskIds }
  })
}

// 批量停止任务
export function batchStopTasks(taskIds, savepoint = false) {
  return request({
    url: '/task/stop/batch',
    method: 'post',
    data: { taskIds, savepoint }
  })
}

// 获取任务表数据
export function getTaskTables(id) {
  return request({
    url: `/task/showTables/${id}`,
    method: 'get'
  })
}

// 获取 kafka lag 数据
export function showKafkaLag(id) {
  return request({
    url: `/task/showKafkaLag/${id}`,
    method: 'get'
  })
}